package com.app.car.set;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.widget.AppCompatCheckBox;

import com.app.car.R;
import com.app.car.home.HomeBaseActivity;
import com.app.car.util.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/***
 * 设置
 * **/
public class SetActivity extends HomeBaseActivity {


    @BindView(R.id.line_one)
    AppCompatCheckBox checkBoxOne;
    @BindView(R.id.line_two)
    AppCompatCheckBox checkBoxTwo;
    @BindView(R.id.line_three)
    AppCompatCheckBox checkBoxThree;
    @BindView(R.id.line_four)
    AppCompatCheckBox checkBoxFour;
    @BindView(R.id.edit_power)
    EditText edit_power;





    @Override
    public void initViews() {
        // TODO Auto-generated method stub
        super.initViews();
        setContentView(R.layout.set_activity);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.initData(savedInstanceState);
        edit_power.setText(""+MyUtils.getPower());

        for (int value:MyUtils.getAirWire()) {
            switch (value){
                case 1:
                    checkBoxOne.setChecked(true);
                    break;
                case 2:
                    checkBoxTwo.setChecked(true);
                    break;
                case 3:
                    checkBoxThree.setChecked(true);
                    break;
                case 4:
                    checkBoxFour.setChecked(true);
                    break;
            }
        }

    }

    @OnClick({R.id.btn_save})
    public void btnClick(View v) {
        switch (v.getId()){
            case R.id.btn_save:
                List<Integer> checkIndex = new ArrayList<>();
                if(checkBoxOne.isChecked()){
                    checkIndex.add(1);
                }
                if(checkBoxTwo.isChecked()){
                    checkIndex.add(2);
                }
                if(checkBoxThree.isChecked()){
                    checkIndex.add(3);
                }
                if(checkBoxFour.isChecked()){
                    checkIndex.add(4);
                }
                MyUtils.putAirWire(checkIndex);
                MyUtils.putPower(Integer.valueOf(edit_power.getText().toString()));
                showToast("保存成功");

                break;
        }

    }



}
